package cn.classba.hive.io.format;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.*;

import java.io.IOException;

@InterfaceAudience.Public
@InterfaceStability.Stable
public class MultiDelimitFileInputFormat extends TextInputFormat {

    @Override
    public RecordReader<LongWritable, Text> getRecordReader(
            InputSplit genericSplit, JobConf job,
            Reporter reporter)
            throws IOException {

        reporter.setStatus(genericSplit.toString());
        String delimiter = job.get("textinputformat.record.delimiter");
        byte[] recordDelimiterBytes = "|$^_^$|".getBytes("UTF-8");
        if (null != delimiter  && "".equals(delimiter)) {
            recordDelimiterBytes = delimiter.getBytes("UTF-8");
        }
        return new LineRecordReader(job, (FileSplit) genericSplit,
                recordDelimiterBytes);
    }
}
